#!/bin/bash

echo "please input file 1:"
read file1
echo "please input file 2:"
read file2
rm -rf 1to2.txt 2to1.txt

awk '{print $1$2$3$4$5}' $file1 >  .awk1
awk '{print $1$2$3$4$5}' $file2 >  .awk2
awk '{print $2$1$3$4$5}' $file1 >  .awk3
awk '{print $2,$1,$3,$4,$5}' $file1 >  .awk4

sort -u .awk1 > .tmp1
sort -u .awk2 > .tmp2
sort -u .awk3 > .tmp3

cp $file1 .cp1
cp .awk4  .cp2

sort -u .cp1 > .tmp4
sort -u .cp2 > .tmp6

analyse(){
	while read line
	do
		if [ `grep $line $2 | wc -l` -ne "0" ]
		then
			head -1 $4 >> $3
			sed -i '1d' $4
			grep $line $2 | wc -l >> $3
			echo "-----------------------------------------------------------------" >> $3
			echo "" >> $3
		fi
	done < $1
}

analyse ".tmp1" ".awk2" "1to2.txt" ".tmp4"
analyse ".tmp3" ".awk2" "2to1.txt" ".tmp6"
rm -rf .awk* .tmp* .cp*
